package com.ys.tdm.service.item.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ys.tdm.bean.item.Item;
import com.ys.tdm.dao.item.IItemDao;
import com.ys.tdm.service.item.IItemService;
import com.ys.tdm.util.PagerModel;
import com.ys.tdm.util.Query;
import com.ys.tdm.util.StringTools;




/**
 * 模块信息Service实现
 * @author Troy
 * @date 2017-12-27 15:48:30
 */
@Service
public class ItemServiceImpl implements IItemService {

	@Resource
	private IItemDao itemDao;

	@Override
	public Item getItemById(String id) throws Exception {
		return StringUtils.isNotBlank(id) ? this.itemDao.getItemById(id.trim()) : null;
	}

	@Override
	public List<Item> getItemByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		return StringUtils.isNotBlank(ids) ? this.itemDao.getItemByIds(ids) : null;
	}
	
	@Override
	public List<Item> getItemByIdsList(List<String> ids) throws Exception {
		return CollectionUtils.isNotEmpty(ids) ? this.itemDao.getItemByIdsList(ids) : null;
	}

	@Override
	public List<Item> getAll(Item item) throws Exception {
		return null != item ? this.itemDao.getAll(item) : null;
	}

	
	@Override
	public int getByPageCount(Item item)throws Exception {
		return (null != item) ? this.itemDao.getByPageCount(item) : 0;
	}

	@Override
	public void insertItem(Item item) throws Exception {
		this.itemDao.insertItem(item);
	}
	
	@Override
	public void insertItemBatch(List<Item> items) throws Exception {
		this.itemDao.insertItemBatch(items);
	}
	
	@Override
	public void delItemById(String id) throws Exception {
		if (StringUtils.isNotBlank(id)) {
			this.itemDao.delItemById(id.trim());
		}
	}
	
	@Override
	public void delItemByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		if(StringUtils.isNotBlank(ids)){
			this.itemDao.delItemByIds(ids);
		}
	}
	
	@Override
	public void delItemByIdsList(List<String> ids) throws Exception {
		if(CollectionUtils.isNotEmpty(ids)){
			this.itemDao.delItemByIdsList(ids);
		}
	}

	@Override
	public int updateItem(Item item) throws Exception {
		return this.itemDao.updateItem(item);
	}
	
	@Override
	public int updateItemByIds(String ids,Item item) throws Exception {
		return this.itemDao.updateItemByIds(ids, item);
	}
	
	@Override
	public int updateItemByIdsList(List<String> ids,Item item) throws Exception {
		return this.itemDao.updateItemByIdsList(ids, item);
	}
	
	@Override
	public int updateItemList(List<Item> items) throws Exception {
		return this.itemDao.updateItemList(items);
	}
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成"'1','2','3','4'..."这种形式
	 * @param strs
	 * @return
	 
	private String converString(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				StringBuffer sbf = new StringBuffer("");
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						sbf.append("'").append(str.trim()).append("'").append(",");
					}
				}
				if (sbf.length() > 0) {
					sbf = sbf.deleteCharAt(sbf.length() - 1);
					return sbf.toString();
				}
			}
		}
		return "";
	}*/
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成List<String> 集合
	 * 
	 * @param strs
	 * @return
	 
	private List<String> converStringToList(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				List<String> strsList = new ArrayList<String>();
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						strsList.add(str.trim());
					}
				}
				if (strsList.size() > 0) {
					return strsList;
				}
			}
		}
		return null;
	}
	*/
	
	//------------api------------
	
}

